<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>		
	</head>

	<body>

		<div class="breadcrumbnav">
			<span class="layui-breadcrumb " lay-separator="·">
          <a ><cite>首页</cite></a>
           <a ><cite>线下销售</cite></a>
          <a ><cite>经手人</cite></a>
        </span>
		</div>
		<div class="kit-doc">
			<!-- 标题 -->

			<div class="kit-doc-title">

				<fieldset>
					<legend>
						<a name="blockquote">经手人</a>
					</legend>
				</fieldset>
			</div>
			<!-- 标题 end-->

			<!-- 概述 -->
			<div class="boderbox">
				<div class="rowtop">
					<button class="layui-btn addbtn openwinbtn" data-method="addmang">添加+</button>
					<button class="layui-btn addbtn openwinbtn layui-bg-blue hidediv" id="yeschoice"  data-method="yeschoice">确认选择</button>
					<!--<form class="layui-form searchform" action="" id="comSearchForm">
						<select name="city" lay-verify="" id="serchselect">
							<option value="barCode">条码</option>
							<option value="commodityBrand">品牌</option>
							<option value="commodityName">名称</option>
						</select>
						<div class="layui-input-inline">
							<input type="text" name="text" required lay-verify="required" placeholder="输入关键字" autocomplete="off" class="layui-input" id="demoReload">
						</div>
						<div class="layui-btn-group">
							<div class="layui-btn openwinbtn" data-method="reload">搜索</div>
							<div class="layui-btn layui-btn-normal openwinbtn" data-method="returnTable">重置</div>
						</div>
					</form>-->
				</div>
				<div class="layui-tab-item layui-show">
					<table class="layui-table " lay-filter="table100" id="VIPtable"></table>

				</div>
				<!--</div>-->
				<script src="js/jquery-3.2.1.min.js"></script>
				<script type="text/javascript" src="js/allajax.js"></script>
				<script id="addBox" type="text/html">
					<!--增加新的分类的html内容-->
					<div class=" layui-layer-wrap">
                        <form class="layui-form layui-form-pane" action="" id="addform" >
                            <!--<div class="layui-form-item">
							    <label class="layui-form-label">编号</label>
							    <div class="layui-input-block">
							      <input type="text" name="realityUserName" autocomplete="off" placeholder="" class="layui-input">
							    </div>
							</div>-->
                            <div class="layui-form-item" >
							    <label class="layui-form-label">姓名</label>
							    <div class="layui-input-block">
							       <input type="text" name="undertookName" autocomplete="off" placeholder="" class="layui-input">
							    </div>
							  </div>
                        </form>
                    </div>
				</script>
				<script>
					layui.use(['layer', 'form', 'element', 'table', 'upload'], function() {
						var layer = layui.layer,
							form = layui.form,
							element = layui.element,
							table = layui.table,
							upload = layui.upload;
						var tableArray = new Array();
						VListFn();

						function VListFn() {
							//获取会员名单	
							AjaxPostFn("system/undertookStaff/select?page=0&pagesize=100", "{}", function(data) {
								tableArray = new Array();
								if(data.htmlState.status==200){
									
									$.each(data.dataResultList, function(idx, obj) {
										console.log(obj.undertookId)
										tableArray.push({
							               
							                "operation": '<a class="layui-btn layui-btn-danger " lay-event="delthis" >删除</a>',
							                "undertookId":obj.undertookId,
							                "undertookName":obj.undertookName
						              	})
									})
									
								}

								//展示已知数据
								var tableIns = table.render({
									elem: '#VIPtable',
									cols: [
										[ //标题栏
										{type:'numbers',fixed: 'left',title: '行号'},
										{type:'checkbox',fixed: 'left'},
											{
												field: 'operation',
												width: 200,
												title: '操作',
												fixed: 'left'
											}, {
												field: 'undertookId',
												width: 300,
												title: '编号'
											}, {
												field: 'undertookName',
												width: 200,
												title: '经手人姓名'
											}

										]
									],
									data: tableArray,
									id: 'VIPtable',
									size: 'lg',
									height: 'full-250',
									even: true,
									page: true, //是否显示分页
									done: function() {
										//图片点击放大
										TopimgFn();
									}
								});
							});

						}
						
						
						table.on('tool(table100)', function(obj) {
							var data = obj.data;
							if(obj.event === 'delthis') {
//								删除
								layer.confirm('是否删除该用户', function(index) {
									AjaxPostFn('system/undertookStaff/deleteUserMessage', "{'undertookId':'" + data.undertookId + "'}", function(jsonData) {
										if(jsonData.htmlState.status == 200) {
											layer.msg("删除成功");
										} else {
											layer.msg(jsonData.htmlState.message);
										}
									});
									obj.del();
									layer.close(index);
								});
							}
						})
						
						//监听单元格编辑
						table.on('edit(table100)', function(obj) {
							var value = obj.value //得到修改后的值
								,data = obj.data //得到所在行所有键值
								,field = obj.field; //得到字段
								
					
//							AjaxPostFn('system/real/user/update', JSON.stringify(data), function(jsonData) {
//								if(jsonData.htmlState.status == 200) {
//									layer.msg("修改成功");
//								}
//							})
					
						});
						
						
						//打开新弹框的事件处理
						$('.openwinbtn').on('click', function() {
							var othis = $(this),
								method = othis.data('method');
							active[method] ? active[method].call(this, othis) : '';
						});
					
						var active = {
							// 弹出框事件
							addmang: function() {
								//添加新的线下用户
								layer.open({
									type: 1,
									skin: 'layui-layer-molv',
									title: '新增线下用户',
									area: ['400px', '200px'],
									content: $("#addBox").html(),
									skin: 'demo-class',
									btn: ["确认新增", "关闭"],
									yes: function(index, layero) {
										
										inputisNull("#addform input", function() {
											var thisdata = $("#addform").serializeJson();
											thisdata.totalConsumption = "0";
											thisdata.orderQuantity = "0" ;
											thisdata.addTime = new Date().getTime();
											AjaxPostFn('system/undertookStaff/generateUserMessage', JSON.stringify(thisdata), function(jsonData) {
												if(jsonData.htmlState.status == 200) {
													layer.msg("增加成功");
//													location.reload();
													VListFn()
													layer.close(index);
												}
											},index)
										})
										
									},success: function() {
									}
								})
							},yeschoice:function(){ 
	
							 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
							 	var checkStatus = table.checkStatus('VIPtable')
							      ,data = checkStatus.data;
							      if(data.length < 1 ){
							      	layer.msg("请选择至少一件商品")
							      }else{
							   
							      	var stockInstr ;
							      
							      	parent.$("#salesSelect").val(data[0].undertookName);
							      	parent.$(".undertookId").val(data[0].undertookId);
							      	//图片点击放大
						           
								   	parent.layer.close(index);
				
							    }
							}
						}
						
					});
				</script>
			</div>
			<!-- 概述 end-->
		</div>
	</body>

</html>